import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
import router from './router/index'


const instance = axios.create({
  baseURL: "http://localhost:3000"
})

Vue.prototype.$axios = instance;
Vue.config.productionTip = false

Vue.use(ElementUI);

axios.interceptors.request.use(
  config => {
    console.log(config) 
    config.headers.Authorization = store.state.token
    return config 
  },
  error => { 
    return Promise.reject(error)
  }
)

// 定义响应拦截器 
axios.interceptors.response.use(function (response) {
  return response
}, function (error) {
  if (error.response.status === 401) {
    store.commit('updateToken', '')
    router.push('/login')
  }
  return Promise.reject(error)
})


new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
